#!/usr/bin/env python
# encoding: utf-8


from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json


class AliyunSmsService():

    @staticmethod
    def sendSms(PhoneNumbers, code):
        """阿里云短信服务：模板 SMS_131805028"""
        client = AcsClient('LTAIladSpmac77xu', 'VHkHUvefMkckhYoJKJf9POBsDrPTID', 'cn-hangzhou')

        request = CommonRequest()
        request.set_accept_format('json')
        request.set_domain('dysmsapi.aliyuncs.com')
        request.set_method('POST')
        request.set_protocol_type('https') # https | http
        request.set_version('2017-05-25')
        request.set_action_name('SendSms')

        request.add_query_param('RegionId', "cn-hangzhou")
        request.add_query_param('PhoneNumbers', PhoneNumbers)
        request.add_query_param('SignName', "四川中测辐射科技有限公司")
        request.add_query_param('TemplateCode', "SMS_131805028")
        request.add_query_param('TemplateParam', "{code:%s}"%code)

        response = client.do_action(request)
        return json.loads(str(response, encoding = 'utf-8'))

